package com.cssw.fyzb.core.dao.turntable;
import com.cssw.fyzb.core.model.dodb.Acct;
import com.cssw.fyzb.core.model.dodb.TurntableWin;
import org.springframework.stereotype.Repository;

import java.util.Date;

@Repository
public class TurntableWinDaoImpl implements TurntableWinDao {

    @Override
    public Long addTurnWinLog(Long logId, Long userId, Long turntableId, String type, String turntableName, String thumb, String status) {
        TurntableWin turntableWin = new TurntableWin();
        turntableWin.setLogId(logId);
        turntableWin.setUserId(userId);
        turntableWin.setTurntableId(turntableId);
        turntableWin.setType(type);
        turntableWin.setTurntableName(turntableName);
        turntableWin.setThumb(thumb);
        Date now = new Date();
        turntableWin.setStatus(status);
        turntableWin.setCreateTime(now);
        turntableWin.save();
        return turntableWin.getWinId();
    }

    @Override
    public TurntableWin getTurnAgainWinLog(Long userId) {
        String sql = "select * from t_turntable_win where type='1' and status='1' and user_id = ?";
        return TurntableWin.dao.findFirst(sql, userId);
    }

    @Override
    public void updateTurnAgainWinLog(TurntableWin turntableWin) {
        if (turntableWin != null) {
            turntableWin.setStatus("2");
            turntableWin.update();
        }
    }
}

